package community.service.impl;

import java.util.ArrayList;

import community.dal.DatabaseSession;
import community.dao.ITopicDao;
import community.dao.impl.TopicDao;
import community.domain.Topic;
import community.exception.DatabaseException;
import community.service.IQuestionService;
import community.service.ITopicService;

public class TopicService implements ITopicService {

	ITopicDao topicDao = new TopicDao();
	IQuestionService questionService = new QuestionService();
	@Override
	public ArrayList<Topic> getTopic() throws DatabaseException {
		try (DatabaseSession databaseSession = new DatabaseSession()) {
			ArrayList<Topic> topics = topicDao.getTopic(databaseSession);
			for (Topic topic : topics) {
				topic.setQuestions(questionService.getQuestion(topic.getTid()));
			}
			return topics;
		}
	}
}
